package cn.com.elite;

import java.rmi.RemoteException;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;

import sfmi.component.chnchannel.chncallcenter.client.CommonClient;
import sfmi.component.chnchannel.chncallcenter.client.FreeInsuranceClient;
import sfmi.component.chnchannel.chncallcenter.dto.common.Code;
import sfmi.component.chnchannel.chncallcenter.dto.common.Name;
import sfmi.component.chnchannel.chncallcenter.dto.common.key.CodeSearchKey;
import sfmi.component.chnchannel.chncallcenter.dto.enums.ConnectMode;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.FICoverage;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.FIPolicyholder;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.FIProduct;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.FIQuotation;
import sfmi.component.chnchannel.chncallcenter.dto.freeinsurance.key.FIQuotationKey;
import sfmi.component.chnchannel.chncallcenter.exception.ChnChannelException;

public class sanTest {
	public static void main(String[] args) throws RemoteException, ChnChannelException{
//		FIQuotationKey fiQuotationKey = new FIQuotationKey();
//		fiQuotationKey.setIpAddress("127.0.0.1");
//		fiQuotationKey.setCouponNo("PH00100102731");
//		FIPolicyholder policyholder = new FIPolicyholder();
//		Name name = new Name(); 
//		name.setName("张三");
//		policyholder.setName(name);
//		policyholder.setNoTypeCode("01");
//		policyholder.setNo("110101197701014798");
//		policyholder.setPhoneNo("13499900903");
//		policyholder.setEmail("11@11.com");
//		policyholder.setMainLocationCode("110");
//		policyholder.setAddress("北京市海淀区");
//		policyholder.setCarOwnerYn("N");
//		policyholder.setAge(36);
//		policyholder.setBirthDate("19770101");
//		policyholder.setSex("1");
//		fiQuotationKey.setPolicyholder(policyholder);
//		FreeInsuranceClient freeInsuranceClient = new FreeInsuranceClient(ConnectMode.DevServer);
//		FIQuotation f=freeInsuranceClient.saveQuotation(fiQuotationKey);
//		System.out.println(f.getCouponId());
//		System.out.println(f.getCouponNo());
//		System.out.println(f.getPolicyNo());
//		System.out.println(f.getQuotationNo());
//		System.out.println(f.getSelfCheckYn());
//		System.out.println(f.getClauseList());
//		System.out.println(f.getCoverageList());
//		System.out.println(f.getPolicyholder());
//		System.out.println(f.getProduct());
//		System.out.println(f.getStatus());
		
//		System.out.println("-----Query Start-----");
//		
//		FIQuotationKey fiQuotationKey1 = new FIQuotationKey();
////		fiQuotationKey1.setQuotationNo("N30213050006900");
//		fiQuotationKey1.setCouponNo("PH00100009304");
//		fiQuotationKey1.setIpAddress("127.0.0.1");
//		FreeInsuranceClient freeInsuranceClient = new FreeInsuranceClient(ConnectMode.DevServer);
//		FIQuotation f=freeInsuranceClient.findQuotation(fiQuotationKey1);
//		System.out.println(f.getCouponId());
//		System.out.println(f.getCouponNo());
//		System.out.println(f.getPolicyNo());
//		System.out.println(f.getQuotationNo());
//		System.out.println(f.getSelfCheckYn());
//		System.out.println(f.getClauseList());
//		System.out.println("f.getCoverageList():"+f.getCoverageList());
//		System.out.println(f.getPolicyholder());
//		System.out.println(f.getProduct());
//		System.out.println(f.getStatus());
//		FIProduct fi=f.getProduct();
//		System.out.println(fi.getInputDate());
//		System.out.println(fi.getPolicyEndDate());
//		System.out.println(fi.getPolicyStartDate());
//		System.out.println(fi.getProductCode());
//		System.out.println(fi.getProductName());
//		System.out.println(fi.getRemarks());
//		System.out.println(fi.getWrittneDate());
//		
//		List list=f.getCoverageList();
//		if(list!=null&&list.size()>0){
//			for(int i=0;i<list.size();i++){
//				FICoverage fi1=(FICoverage)list.get(i);
//				if(fi1!=null){
//					System.out.println(fi1.getCode());
//					System.out.println(fi1.getDeductibleAmount());
//					System.out.println(fi1.getDeductibleCurrency());
//					System.out.println(fi1.getDetail());
//					System.out.println(fi1.getEnglishName());
//					System.out.println(fi1.getLolCurrency());
//					System.out.println(fi1.getLolLimitAmount());
//					System.out.println(fi1.getName());
//
//				}
//			}
//			
//		}
		
//		FIQuotationKey fiQuotationKey1 = new FIQuotationKey();
//		fiQuotationKey.setQuotationNo("N30213050006900");
//		fiQuotationKey.setIpAddress("127.0.0.1");
//		fiQuotationKey.setMainLocationCode("110");
//		FreeInsuranceClient freeInsuranceClient1 = new FreeInsuranceClient(ConnectMode.DevServer);
//		FIQuotation fiQuotation = freeInsuranceClient.confirmQuotation(fiQuotationKey);
//		System.out.println(fiQuotation.getAgreeYn());
//		System.out.println(fiQuotation.getCouponId());
//		System.out.println(fiQuotation.getCouponNo());
//		System.out.println(fiQuotation.getPolicyNo());
//		System.out.println(fiQuotation.getQuotationNo());
//		System.out.println(fiQuotation.getSelfCheckYn());
//		System.out.println(fiQuotation.getClauseList());
//		System.out.println(fiQuotation.getCoverageList());
//		System.out.println(fiQuotation.getStatus());
		
//		CommonClient commonClient = new CommonClient(ConnectMode.DevServer);
//        CodeSearchKey codeSearchKey = new CodeSearchKey();		
//        codeSearchKey.setUserID("join");
//        codeSearchKey.setIpAddress("127.0.0.1");
//        codeSearchKey.setCodeNo("40");
//        
//        List<Code> codeList = null;
//        try {
//            codeList = commonClient.findCommonCodeList(codeSearchKey);
//            if(codeList!=null&&codeList.size()>0){
//            	for(int i=0;i<codeList.size();i++){
//            		Code code=codeList.get(i);
//            		System.out.println(code.getCode());
//            		System.out.println(code.getDetail());
//            		System.out.println(code.getEnglishName());
//            		System.out.println(code.getName());
//            		
//            	}
//            }
//        }catch (ChnChannelException ex) {
//            ex.getId();
//            ex.getMessage();
//        }
		
		

		try{
			String UserID="join";
			String CodeNo="40";
			String IP="127.0.0.1";
			sanTest sanTest1=new sanTest();
			String a=sanTest1.findCommonCodeListImpl(UserID, CodeNo, IP);
			System.out.println(a);
		}catch(Exception e){
            e.printStackTrace();
		}
		
	}
	public String findCommonCodeListImpl(String UserID,String CodeNo,String IP) throws Exception{
		String returnxml="";
		CommonClient commonClient = new CommonClient(ConnectMode.DevServer);
        CodeSearchKey codeSearchKey = new CodeSearchKey();		
        codeSearchKey.setUserID(UserID);
        codeSearchKey.setIpAddress(IP);
        codeSearchKey.setCodeNo(CodeNo);
        List<Code> codeList=commonClient.findCommonCodeList(codeSearchKey);
        if(codeList!=null&&codeList.size()>0){
        	Document result=Util.getDoc();
        	Element root=result.addElement("Result");
        	for(int i=0;i<codeList.size();i++){
        		Code code=codeList.get(i);
        		Element R=root.addElement("R");
        		R.addElement("Code").addText(code.getCode());
        		R.addElement("EnglishName").addText(code.getEnglishName());
        		R.addElement("Name").addText(code.getName());
        	}
        	returnxml=result.asXML();
        }	
		return returnxml;
	}

}